<template>
  <div class="page">
    <!--pages/details/details.wxml-->
    <div v-if="vaccinationInfos.length > 0" class="flex">
      <div class="tr title">
        <div class="td">{{ name | nameChange }}</div>
        <div class="td" style="color: black">
          {{ sfzh | personNumberChange }}
        </div>
      </div>
      <div class="card" v-for="(item, index) in vaccinationInfos" :key="index">
        <div class="tr">
          <div class="td">第{{ item.vaccinationTime }}针</div>
        </div>
        <div class="tr">
          <div class="td">疫苗名称：</div>
          <div class="td">{{ item.vacName }}</div>
        </div>
        <div class="tr">
          <div class="td">疫苗生产商：</div>
          <div class="td">{{ item.vaccineProducerName }}</div>
        </div>
        <div class="tr">
          <div class="td">接种单位：</div>
          <div class="td">{{ item.vaccinationUnitName }}</div>
        </div>
        <div class="tr">
          <div class="td">接种日期：</div>
          <div class="td">{{ item.vaccinationDateTime | timeFiter  }}</div>
        </div>
      </div>
    </div>
    <button class="retun" @click="okRet">返 回</button>
  </div>
</template>

<script>
import {parseTime} from "@/utils/AESUtils";

let changeStr = function (str, index, changeStr) {
  return (
    str.substring(0, index) +
    changeStr +
    str.substring(index + changeStr.length)
  );
};
export default {
  data() {
    return {
      name: "",
      sfzh: "",
      vaccinationInfos: [],
    };
  },

  created() {
    let data = JSON.parse(
      decodeURIComponent(this.$route.query.vaccinationInfos)
    );
    this.vaccinationInfos = data;
    this.name = data[0].recipientName;
    this.sfzh = data[0].recipientIdNumber;
  },
  filters: {
    nameChange(e) {
      if (e) {
        if (e.length > 3) {
          e = changeStr(e, 0, "*");
          e = changeStr(e, 1, "*");
        } else {
          e = changeStr(e, 0, "*");
        }
      } else {
        e = "无";
      }
      return e;
    },
    personNumberChange(e) {
      // 身份证
      if (e) {
        if (e.length == 18) {
          e = e.substring(0, 6) + "********" + e.substring(14, 18);
        } else if (e.length == 15) {
          e = e.substring(0, 4) + "********" + e.substring(11, 15);
        } else if (e.length >= 4 && e.length != 15 && e.length != 18) {
          e = e.substring(0, 4) + "****";
        }
      }
      return e;
    },
    timeFiter(e) {
      if (typeof(e) === 'string') {
        return e.substring(0, 10);
      } else if (typeof(e) === 'number') {
        return parseTime(e).substring(0, 10);
      } else {
        return null;
      }
    },
  },
  methods: {
    okRet() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="scss" scoped>
/* pages/details/details.wxss */
.page {
  background: #f7f8fa;
  min-height: 100vh;
}
.retun {
  width: 80%;
  height: 60px;
  text-align: center;
  line-height: 60px;
  padding: 0;
  background: #cccccc;
  color: white;
  font-size: 25px;
  font-weight: bold;
  border-radius: 25px;
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translate(-50%, 0);
  border: 0;
}
.card {
  margin: 0 16px;
  overflow: hidden;
  margin-top: 40px;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  width: 90%;
  padding: 10px 16px;
  background-color: #fff;
  box-sizing: border-box;
}
.card:nth-last-child(1) {
  margin-bottom: 80px;
}
.flex {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.u {
  width: 80%;
  border-bottom: 1px solid #ebedf0;
}

.title {
  width: 90% !important;
  justify-content: space-between !important;
  padding: 20px !important;
  font-size: 25px !important;
  margin-top: 20px;
}

.tr {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: start;
  box-sizing: border-box;
  width: 100%;
  overflow: hidden;
  color: #323233;
  background-color: #fff;
  font-size: 20px;
  padding: 5px;
}
.tr .td:nth-child(1) {
  min-width: 120px;
}

.tr .td:nth-child(2) {
  color: #898989;
}
.yuan {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: white;
  line-height: 30px;
  text-align: center;
  font-size: 16px;
}

.logoBox {
  position: fixed;
  bottom: 5%;
  left: 50%;
  transform: translate(-50%, 0);
  font-size: 20px;
  color: #1b7afb;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: -9;
}

.logo {
  width: 30px;
  height: 30px;
  margin-right: 15px;
}
</style>
